package com.gxa.logistics.common.util;

import com.gxa.logistics.domain.dto.UserDTO;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class JwtUtil {
    private static final String SECRET_KEY = "leo"; // 请替换为你的密钥
    private static final long EXPIRATION_TIME = 86400000; // 1天，以毫秒为单位

    public static String generateToken(UserDTO userDTO) {
        return Jwts.builder()
                .setSubject(userDTO.getUsername())
                .setIssuedAt(new Date())
                .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
                .signWith(SignatureAlgorithm.HS512, SECRET_KEY)
                .compact();
    }
}
